package com.charlotte.gupao.study.logserviceprovider.dubbo.demo.provider;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.charlotte.gupao.study.logserviceprovider.dubbo.entity.SysLog;
import com.charlotte.gupao.study.logserviceprovider.dubbo.mapper.SysLogMapper;
import com.charlotte.study.api.LogService;
import com.charlotte.study.dto.LogDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.List;

/**
 * @author junjie.ding
 * @date 2020/9/9 9:45
 * @description TODO
 */
@Service(protocol = "dubbo")
public class LogServiceImpl implements LogService {

    @Autowired
    private SysLogMapper logMapper;

    @Override
    public boolean insertLog(LogDto dto) {
        SysLog log = new SysLog();
        log.setId(dto.getLogId());
        log.setName(dto.getLogClassName());
        log.setContent(dto.getLogContent());
        int insert = logMapper.insert(log);
        return insert > 0;
    }

    @Override
    public List<Object> queryLog() {
        return Collections.singletonList(logMapper.selectList(new QueryWrapper<>()));
    }
}
